
package com.e885.webservice;

import javax.servlet.http.HttpServletRequest;

import com.e885.exception.E885WebserviceException;
import com.e885.log.E885Logger;

/**
 * 有用到的 webservice 都可繼承這個 class
 * 
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2001-2008
 */
public abstract class CommonWebService
{
	private String remoteAddr;

	private Object soap;

	protected boolean isTest = true;

	public CommonWebService()
	{
		E885Logger.webserviceLog.debug( "***** Webserive is Test *****" );
	}

	public CommonWebService( HttpServletRequest reuest, String soapName, Class soapClass, String url )
	{
		remoteAddr = reuest.getRemoteAddr();

		E885Logger.webserviceLog.debug( "���ݦ�s遠端位址(remoteHost):[" + remoteAddr + "]" );

		if( remoteAddr != null && remoteAddr.equals( "127.0.0.1" ) )
			E885Logger.webserviceLog.debug( "***** Webserive is Test *****" );
		else
		{
			isTest = false;

			soap = new WebServiceClient( url, soapName, soapClass ).getSoap();
		}
	}

	public CommonWebService( String url, String soapName, Class soapClass )
	{
		soap = new WebServiceClient( url, soapName, soapClass ).getSoap();

		isTest = false;
	}

	/**
	 * 呼叫 webservice method 和取得傳回值, 並將傳回傳做有效的處理
	 * 
	 * @param bean
	 * @throws E885WebserviceException
	 */
	public void doWebService( AbstractParameter bean ) throws E885WebserviceException
	{
		doWebServiceAction( bean, soap );
	}

	/**
	 * 呼叫 webservice method 和取得傳回值, 並將傳回傳做有效的處理
	 * 
	 * @param bean
	 * @param soap
	 * @throws E885WebserviceException
	 */
	protected abstract void doWebServiceAction( AbstractParameter bean, Object soap ) throws E885WebserviceException;
}
